/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nl.maxato.services;

import java.util.ArrayList;
import java.util.List;

import nl.maxato.domain.*;
import nl.maxato.xmlservices.ConvertXMLData;

/**
 *
 * @author Danny
 */
public class CalculateDifferencesAthletes {

    List<Differences> dfs;
    ConvertXMLData xdv;
    int age;
    int wage;
    int fans;
    int height;
    int weight;
    int maxid;
    int experience;
    int strenght;
    int stamina;
    int speed;
    int agility;
    int jump;
    int throwing;
    int specialty1;
    int specialty2;

    public CalculateDifferencesAthletes() {
        dfs = new ArrayList<Differences>();
        xdv = new ConvertXMLData();
        setValueNull();
    }

    private void setValueNull() {
        age = 0;
        wage = 0;
        fans = 0;
        height = 0;
        weight = 0;
        maxid = 0;
        experience = 0;
        strenght = 0;
        stamina = 0;
        speed = 0;
        agility = 0;
        jump = 0;
        throwing = 0;
        specialty1 = 0;
        specialty2 = 0;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getAgility() {
        return agility;
    }

    public void setAgility(int agility) {
        this.agility = agility;
    }

    public int getExperience() {
        return experience;
    }

    public void setExperience(int experience) {
        this.experience = experience;
    }

    public int getFans() {
        return fans;
    }

    public void setFans(int fans) {
        this.fans = fans;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getJump() {
        return jump;
    }

    public void setJump(int jump) {
        this.jump = jump;
    }

    public int getMaxid() {
        return maxid;
    }

    public void setMaxid(int maxid) {
        this.maxid = maxid;
    }

    public int getSpecialty1() {
        return specialty1;
    }

    public void setSpecialty1(int specialty1) {
        this.specialty1 = specialty1;
    }

    public int getSpecialty2() {
        return specialty2;
    }

    public void setSpecialty2(int specialty2) {
        this.specialty2 = specialty2;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public int getStamina() {
        return stamina;
    }

    public void setStamina(int stamina) {
        this.stamina = stamina;
    }

    public int getStrenght() {
        return strenght;
    }

    public void setStrenght(int strenght) {
        this.strenght = strenght;
    }

    public int getThrowing() {
        return throwing;
    }

    public void setThrowing(int throwing) {
        this.throwing = throwing;
    }

    public int getWage() {
        return wage;
    }

    public void setWage(int wage) {
        this.wage = wage;
    }

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }

    public List<Differences> compareXMLFiles(List<Athlete> listOld, List<Athlete> listNew, int orderBy, List<String> s) {
        setValueNull();
        dfs = new ArrayList<Differences>();
        for (int z = 0; z < listOld.size(); z++) {
            Athlete q = listOld.get(z);
            for (int f = 0; f < listNew.size(); f++) {
                Athlete g = listNew.get(f);
                if (q.getIdOfAthlete() == g.getIdOfAthlete()) {
                    //Atleet objecten zijn nu hetzelfde
                    dfs = compareAthletes(q, g, s);
                }
            }
        }
        if (orderBy != 0) {
            dfs = orderBy(dfs, orderBy);
        }
        return dfs;
    }

    public List<Differences> compareAthletes(Athlete old, Athlete newAthlete, List<String> s) {
        //dfs = new ArrayList<Differences>();
        if (old.getAge() != newAthlete.getAge()) {
            age += (newAthlete.getAge() - old.getAge());
            dfs.add(new Differences(1, s.get(1).toString(), newAthlete, old.getAge(), newAthlete.getAge()));
        }
        if (old.getWage() != newAthlete.getWage()) {
            wage += (newAthlete.getWage() - old.getWage());
            dfs.add(new Differences(2, s.get(2).toString(), newAthlete, old.getWage(), newAthlete.getWage()));
        }
        if (old.getFans() != newAthlete.getFans()) {
            fans += (newAthlete.getFans() - old.getFans());
            dfs.add(new Differences(3, s.get(3).toString(), newAthlete, old.getFans(), newAthlete.getFans()));
        }
        if (old.getHeight() != newAthlete.getHeight()) {
            height += (newAthlete.getHeight() - old.getHeight());
            dfs.add(new Differences(4, s.get(4).toString(), newAthlete, old.getHeight(), newAthlete.getHeight()));
        }
        if (old.getWeight() != newAthlete.getWeight()) {
            weight += (newAthlete.getWeight() - old.getWeight());
            dfs.add(new Differences(5, s.get(5).toString(), newAthlete, old.getWeight(), newAthlete.getWeight()));
        }
        if (old.getMaxid() != newAthlete.getMaxid()) {
            maxid += (newAthlete.getMaxid() - old.getMaxid());
            dfs.add(new Differences(6, s.get(6).toString(), newAthlete, old.getMaxid(), newAthlete.getMaxid()));
        }
        if (old.getForm() != newAthlete.getForm()) {
            experience += (newAthlete.getForm() - old.getForm());
            dfs.add(new Differences(7, s.get(7).toString(), newAthlete, old.getForm(), newAthlete.getForm()));
        }
        if (old.getExperience() != newAthlete.getExperience()) {
            experience += (newAthlete.getExperience() - old.getExperience());
            dfs.add(new Differences(8, s.get(8).toString(), newAthlete, old.getExperience(), newAthlete.getExperience()));
        }
        if (old.getStrenght() != newAthlete.getStrenght()) {
            strenght += (newAthlete.getStrenght() - old.getStrenght());
            dfs.add(new Differences(9, s.get(9).toString(), newAthlete, old.getStrenght(), newAthlete.getStrenght()));
        }
        if (old.getStamina() != newAthlete.getStamina()) {
            stamina += (newAthlete.getStamina() - old.getStamina());
            dfs.add(new Differences(10, s.get(10).toString(), newAthlete, old.getStamina(), newAthlete.getStamina()));
        }
        if (old.getSpeed() != newAthlete.getSpeed()) {
            speed += (newAthlete.getSpeed() - old.getSpeed());
            dfs.add(new Differences(11, s.get(11).toString(), newAthlete, old.getSpeed(), newAthlete.getSpeed()));
        }
        if (old.getAgility() != newAthlete.getAgility()) {
            agility += (newAthlete.getAgility() - old.getAgility());
            dfs.add(new Differences(12, s.get(12).toString(), newAthlete, old.getAgility(), newAthlete.getAgility()));
        }
        if (old.getJump() != newAthlete.getJump()) {
            jump += (newAthlete.getJump() - old.getJump());
            dfs.add(new Differences(13, s.get(13).toString(), newAthlete, old.getJump(), newAthlete.getJump()));
        }
        if (old.getThrowing() != newAthlete.getThrowing()) {
            throwing += (newAthlete.getThrowing() - old.getThrowing());
            dfs.add(new Differences(14, s.get(14).toString(), newAthlete, old.getThrowing(), newAthlete.getThrowing()));
        }
        if (old.getSpecialty1() != newAthlete.getSpecialty1()) {
            specialty1 += (newAthlete.getSpecialty1() - old.getSpecialty1());
            dfs.add(new Differences(15, s.get(15).toString(), newAthlete, old.getSpecialty1(), newAthlete.getSpecialty1()));
        }
        if (old.getSpecialty2() != newAthlete.getSpecialty2()) {
            specialty2 += (newAthlete.getSpecialty2() - old.getSpecialty2());
            dfs.add(new Differences(16, s.get(16).toString(), newAthlete, old.getSpecialty2(), newAthlete.getSpecialty2()));
        }


        return dfs;
    }

    private List<Differences> orderBy(List<Differences> ldfs, int orderBy) {
        List<Differences> listDifferences = new ArrayList<Differences>();
        for (int w = 0; w < ldfs.size(); w++) {
            if (ldfs.get(w).getSortDiscipline() == orderBy) {
                listDifferences.add(ldfs.get(w));
            }
        }
        return listDifferences;
    }
}
